<?php
class Business_RealCategory{
	/**
	 * 
	 * @return Array | Zend_Exception
	 */
	public static function getAllId(){
        try {
            $db = Core_Global::getDatabase();
            $stmt = $db->prepare('CALL sp_getAllRealCategoryId()');
            $stmt->execute();
            $result = $stmt->fetchAll();
            return $result;
        } catch (Zend_Exception $e) {

            return $e->getMessage();
        }
	}
	
	public static function getAllIds($ids){
        try {
            $db = Core_Global::getDatabase();
            $stmt = $db->prepare('CALL sp_getRealCategoryByIds(:p_ids)');
            $stmt->bindValue('p_ids',$ids);
            $stmt->execute();
            $result = $stmt->fetchAll();
            $stmt=null;
            return $result;
        } catch (Zend_Exception $e) {
            return $e->getMessage();
        }
	}
	
	/**
	 * 
	 * @param $params['key'] = RealCategoryID,RealCategoryName | $params['value'] = 1, Name
	 * @return Array
	 */
	public static function get($params){
		
	}


    public static function create($params){
        try {
            $db = Core_Global::getDatabase();
            $stmt = $db->prepare('CALL sp_insertRealCategory(:s_catName,:s_catOrder,:s_catDesc)');
            $stmt->bindValue('s_catName',$params['catName']);
            $stmt->bindValue('s_catOrder',$params['catOrder']);
            $stmt->bindValue('s_catDesc',$params['catDesc']);
            $stmt->execute();
            $result = $stmt->rowCount();
            return $result;
        } catch (Zend_Exception $e) {
            return 0;
        }
    }
	/**
	 * 
	 * @param unknown_type $params
	 * @return number
	 */
	public static function update($params){
		try {
			$db = Core_Global::getDatabase();
			$stmt = $db->prepare('CALL sp_updateRealCategory(:s_CatId,:s_CatName,:s_CatOrder,:s_CatDesc)');
			$stmt->bindValue('s_CatId',$params['catId']);
			$stmt->bindValue('s_CatName',$params['catName']);
			$stmt->bindValue('s_CatOrder',$params['catOrder']);
			$stmt->bindValue('s_CatDesc',$params['catDesc']);
			$stmt->execute();			
			
			$result = $stmt->rowCount();
			
			unset($stmt);
			
			return $result;
		} catch (Zend_Exception $e) {
			return 0;
		}
	}

    public static function delete($catId){
        try {
            $db = Core_Global::getDatabase();
            $stmt = $db->prepare("CALL sp_deleteRealCategorybyIds(:s_CatId)");
            $stmt->bindValue('s_CatId',$catId);
            return $stmt->execute();
        } catch (Zend_Exception $e) {
            return $e->getMessage();
        }
    }
}